/*
 * @Author: your name
 * @Date: 2021-04-22 07:11:15
 * @LastEditTime: 2021-04-26 14:37:00
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \offer20k\项目代码\fantasticit\src\app.ts
 */
import { RequestConfig } from "umi";
import { createLogger } from "redux-logger";
import StoreContext from '@/context/storeContext'
import store from '@/store';
import React from 'react';
const baseURL = 'https://api.blog.wipi.tech'
// 引入viewjs的样式
import 'viewerjs/dist/viewer.css';
export const request: RequestConfig = {
    timeout: 30000,
    //   初始配置
    errorConfig: {},
    //   请求拦截器
    requestInterceptors: [
        (url, options) => {
            if (!/\/\//.test(url)) {
                url = baseURL + url;
            }
            // let headers = {};
            return {
                url,
                options
            };
        },
    ],
    //   响应拦截器
    responseInterceptors: [response => {
        const codeMaps: { [key: string]: string } = {
            400: '错误请求',
            403: '请求禁止访问',
            404: '请求资源不存在',
            500: '服务器内部错误',
            502: '网关错误',
            503: '服务不可用，服务器暂时过载或维护',
            504: '网关超时',
        };
        if (response.status !== 200) {
            // debugger
            console.warn(codeMaps[response.status]);
        }
        return response;
    }],
};
// dva配置
// export const dva = {
//     config: {
//         onAction: createLogger(),
//         onError(err: Error) {
//             console.log(err);
//         },
//     },
// };
// export const dva = {
//     config: {
//       onError(e: { preventDefault: () => void; message: any; }) {
//         e.preventDefault();
//         console.error(e.message);
//       },
//     },
//   };
export function rootContainer(container: any) {
    return React.createElement(StoreContext.Provider, { value: store }, container);
}

